package com.it.springbootjpa.dao;

import com.it.springbootjpa.domain.Contract;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ContractDao extends JpaRepository<Contract, Long> {
//    根据合同编号,合同类型,对方联系人名称查询(前端传入参数)
    @Modifying
    @Query("select c from Contract c where c.contractNum=?1 and c.contractType=?2 and c.name=?3")
    List<Contract> findAllByContractNumAndContractTypeAndName(String contractNum, String contractType, String name);
//通过合同状态和合同开始时间在本月内的条件查询
    //    nativeQuery=true 为原生sql, false为Jsql
    @Query(nativeQuery = true,value = "select * from d_contract c where c.contract_status = ?1 " +
            " and DATE_FORMAT(now(),'%m' ) = DATE_FORMAT(c.contract_start,'%m' )")
    List<Contract> findByContractStatus(Boolean contractStatus);
//    通过分页查询条件 合同编号 每页30条数据
    //    nativeQuery=true 为原生sql, false为Jsql
    @Query(nativeQuery = true,value = "select * from d_contract where " +
            "d_contract.contract_num = ?1  limit ?2,?3")
    List<Contract> findByPage(String contractNo,Integer startIndex,Integer PageSize);
}
